package com.example.index.extension

import android.content.Intent
import android.content.res.Resources
import android.graphics.Color
import android.view.MotionEvent
import android.view.View
import android.view.Window
import android.view.WindowManager
import androidx.fragment.app.FragmentActivity
import com.example.index.App


/*逻辑*/

fun FragmentActivity.quickStartActivity(targetClass: Class<*>) = this.startActivity(Intent(this, targetClass))


val Number.sp: Float get() = (this.toFloat() * Resources.getSystem().displayMetrics.scaledDensity)

val Number.dp:Float  get() = (this.toFloat()*Resources.getSystem().displayMetrics.density)

/*ui*/

fun Window.setImmersive() = run {
    clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
    addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
    decorView.systemUiVisibility =
        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    statusBarColor = Color.TRANSPARENT
}

/*Activity 增强逻辑*/
fun FragmentActivity.string(stringResId:Int)= App.app.getString(stringResId)


fun MotionEvent.ev(): String {
    return when (this.action) {
        MotionEvent.ACTION_DOWN -> "DOWN"
        MotionEvent.ACTION_MOVE -> "MOVE"
        MotionEvent.ACTION_UP -> "UP"
        else -> "UNKNOWN"
    }
}